package com.hutao.medical.controller.print;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.hutao.medical.common.config.ConfigProperties;
import com.hutao.medical.common.util.CookieUtils;
import com.hutao.medical.common.util.DateUtil;
import com.hutao.medical.common.util.ExcelUtil;
import com.hutao.medical.common.util.HttpClientUtil;
import com.hutao.medical.common.util.JsonUtils;
import com.hutao.medical.common.util.ObjectUtils;
import com.hutao.medical.common.util.PDFUtil;
import com.hutao.medical.common.util.Params;
import com.hutao.medical.common.util.Result;
import com.hutao.medical.common.util.StringUtil;
import com.hutao.medical.common.util.WaterMarkUtil;
import com.hutao.medical.pojo.MailRegistraion;
import com.hutao.medical.pojo.RespondResult;
import com.hutao.medical.pojo.dto.PrintPageDto;
import com.hutao.medical.pojo.print.ApplyPrint;
import com.hutao.medical.pojo.print.HospitalNote;
import com.hutao.medical.pojo.print.MedicalMail;
import com.hutao.medical.pojo.print.MedicalPrint;
import com.hutao.medical.pojo.print.PrintApplyImage;
import com.hutao.medical.pojo.print.PrintDetail;
import com.hutao.medical.pojo.print.PrintMailRecord;
import com.hutao.medical.pojo.print.PrintRecord;
import com.hutao.medical.pojo.vo.ApplyPrintVo;
import com.hutao.medical.pojo.vo.PrintCheckVo;
import com.hutao.medical.pojo.vo.PrintRecordVo;
import com.hutao.medical.service.BasicDataService;
import com.hutao.medical.service.TreatmentTraceService;
import com.hutao.medical.service.TreatmentTraceTypeService;
import com.hutao.medical.service.print.ApplyPrintService;

@RequestMapping("/print")
@Controller
public class ApplyPrintController {

	@Autowired
	private ConfigProperties configProperties;

	// public static List<HospitalNote> HOSPITALNOTELIST=new ArrayList<>();
	//
	@Autowired
	private ApplyPrintService applyPrintService;

	@Autowired
	private BasicDataService basicDataService;
	
	@Autowired
	private TreatmentTraceService treatmentTraceService;
	
	@Autowired
	private TreatmentTraceTypeService treatmentTraceTypeService;

	private static final Logger logger = LoggerFactory.getLogger(ApplyPrintController.class);

	@ResponseBody
	@RequestMapping("/config")
	public String testConfig() {
		System.out.println(configProperties.getSso().getLoginPath());
		return configProperties.getSso().getLoginByUserName();
	}


	
	@RequestMapping("/addApplyPrint")
	public String addApplyPrint(ApplyPrint applyPrint, ApplyPrintVo applyPrintVo, HttpServletRequest request) {
		try {

			applyPrint.setUniqueId(StringUtil.getId());
			// 添加打印信息
			applyPrintService.print(applyPrint, applyPrintVo);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-添加打印信息出现错误!");
		}

		return "print/applyPrint";
	}

	/**
	 * 查询申请打印信息
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryApplyPrint")
	public List<Map<String, Object>> queryApplyPrint() {

		List<Map<String, Object>> applyPrintList = new ArrayList<>();

		try {
			// 查询打印申请信息
			applyPrintList = applyPrintService.queryApplyPrint();

		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-查询申请信息出现错误!");
		}

		return applyPrintList;

	}

	/**
	 * 查询打印审核信息
	 * 
	 * @param params
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryApplyCheck")
	public Map<String, Object> queryApplyToCheck(Params params) {

		Map<String, Object> map = new HashMap<>();
		try {
			// 查询打印审核信息
			List<Map<String, Object>> applyCheckList = applyPrintService.queryApplyToCheck(params);
			int count = applyPrintService.queryApplyCheckCount(params);
			map.put("applyCheckList", applyCheckList);
			map.put("count", count);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-查询审核信息出现错误!");
		}

		return map;

	}

	/**
	 * 更新申请打印状态
	 * 
	 * @param applyPrintDetailId
	 * @param status
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateApplyStatus")
	public int updateApplyStatus(String applyPrintDetailId, String status) {
		try {

			// PrintSaoMiao printSaoMiao =
			// applyPrintService.getSaoMiaoMsg(Integer.parseInt(applyPrintDetailId));
			// int prePrintCount =
			// mrInBaiscService.getPrePageCount(printSaoMiao);
			applyPrintService.updateApplyStatus(applyPrintDetailId, status, null);
			return 1;

		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-更新审核状态出现错误!");
			return 0;

		}

	}

	/**
	 * 批量更新打印申请状态
	 * 
	 * @param applyPrintDetailIds
	 *            打印申请详情id
	 * @param status
	 *            打印申请状态
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateBatchApplyStatus")
	public String updateBatchApplyStatus(String applyPrintDetailIds, String status) {
		try {

			if (StringUtil.isNotEmpty(applyPrintDetailIds)) {
				for (String applyPrintDetailId : applyPrintDetailIds.split(",")) {
					// PrintSaoMiao printSaoMiao =
					// applyPrintService.getSaoMiaoMsg(Integer.parseInt(applyPrintDetailId));
					// int prePrintCount =
					// mrInBaiscService.getPrePageCount(printSaoMiao);
					applyPrintService.updateApplyStatus(applyPrintDetailId, status, null);
				}
				return "success";
			} else {
				return "null";
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-批量更新审核状态出现错误!");
			return "fail";
		}

	}

	/**
	 * 获取打印信息
	 * 
	 * @param params
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getPrintList")
	public Map<String, Object> getPrintList(Params params) {

		Map<String, Object> map = new HashMap<>();
		try {

			List<Map<String, Object>> printList = applyPrintService.getPrintList(params);
			int count = applyPrintService.getPrintListCount(params);
			map.put("printList", printList);
			map.put("count", count);

		} catch (Exception e) {

			logger.info("打印申请-获取打印信息出现错误!");
		}

		return map;
	}

	/**
	 * 获取打印信息
	 * 
	 * @param printDetailId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/getPrintInfo/{printDetailId}")
	public String getPrintInfo(@PathVariable("printDetailId") Integer printDetailId,
			@SuppressWarnings("rawtypes") Map map) {

		try {

			PrintDetail printDetail = applyPrintService.getPrintDetail(printDetailId);

			map.put("printDetail", printDetail);
		} catch (Exception e) {

			logger.info("打印申请-获取打印信息出现错误!");
		}

		return "/print/addPrintFee";
	}

	/**
	 * 添加打印详情信息
	 * 
	 * @param printDetail
	 *            打印详情
	 * @param request
	 * @return
	 */
	@RequestMapping("/addPrintMsg")
	public String addPrintMsg(PrintDetail printDetail, HttpServletRequest request) {
		try {

			String printFee = request.getParameter("printFee");
			applyPrintService.addPrintMsg(printDetail, printFee);
		} catch (Exception e) {
			e.printStackTrace();
			logger.info("打印申请-添加打印信息出现错误!");
		}

		return "/print/print";
	}

	/**
	 * 查询打印费用信息
	 * 
	 * @param params
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getPrintFeeMsg")
	public Map<String, Object> getPrintFeeMsg(Params params) {
		Map<String, Object> map = new HashMap<>();
		try {

			List<Map<String, Object>> printFeeMsgList = applyPrintService.getPrintFeeMsg(params);

			int count = applyPrintService.getPrintCountbyParams(params);
			map.put("listSize", printFeeMsgList.size());
			map.put("count", count);
			map.put("printFeeMsgList", printFeeMsgList);
		} catch (Exception e) {

			logger.info("打印申请-查询打印费用信息出现错误!");
		}

		return map;
	}

	/**
	 * 更新收费状态
	 * 
	 * @param printFeeId
	 *            打印收费id
	 * @param status
	 *            收费状态
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateChargeStatus")
	public String updateChargeStatus(Integer printFeeId, Integer status) {
		try {

			applyPrintService.updateChargeStatus(printFeeId, status);
			return "success";
		} catch (Exception e) {

			logger.info("打印申请-更新收费状态出现错误!");
			return "fail";
		}

	}

	/**
	 * 获取打印图片信息
	 * 
	 * @return
	 */

	/**
	 * 跳转到数据打印页面
	 * 
	 * @param medicalOnlyId
	 *            诊疗唯一标示
	 * @param applyReason
	 *            申请原因
	 * @param printDetailId
	 * 
	 *            打印详情id
	 * @param map
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/printPic")
	public String printPic(String medicalOnlyId, Integer applyReason, Integer printDetailId, Map map) {
		map.put("medicalOnlyId", medicalOnlyId);
		map.put("applyReason", applyReason);
		map.put("printDetailId", printDetailId);
		return "/print/printPic";
	}

	@ResponseBody
	@RequestMapping("/updatePrinting")
	public String updatePrintStatus(Integer printDetailId) {
		try {

			int i = applyPrintService.updatePrinting(printDetailId);
			if (i > 0) {
				return "success";
			} else {
				return "null";
			}
		} catch (Exception e) {
			logger.info("打印申请-更新打印状态出现错误!");
			return "fail";
		}

	}

	@SuppressWarnings("unchecked")
	@RequestMapping("/toPrint")
	public String toPrint(String urls, Map map) {
		System.out.println(urls);
		List<String> urlList = new ArrayList<>();
		if (StringUtil.isNotEmpty(urls)) {
			for (String url : urls.split(",")) {
				urlList.add(url);
			}
		}
		System.out.println(urlList.size());
		map.put("urlList", urlList);
		return "/print/toPrint";

	}

	@ResponseBody
	@RequestMapping("/getPrintDetail")
	public PrintDetail getPrintDetail(Integer printDetailId) {
		return applyPrintService.getPrintDetail(printDetailId);
	}

	@ResponseBody
	@RequestMapping("/getUrlListByMedRecord")
	public List<Map<String, Object>> getUrlListByMedRecord(String medicalOnlyId, String applyReason) {
		Map<String, String> params = new HashMap<>();
		params.put("firstGuid", medicalOnlyId);
		params.put("printerType", applyReason);
		// System.out.println(printerType);
		List<Map<String, Object>> imgMapList = new ArrayList<>();
		System.out.println(applyReason);
		String userJson = HttpClientUtil.doGet(configProperties.getMedicalManage().getPicSourcePath(), params);
		Result result = JSONObject.parseObject(userJson, Result.class);
		System.out.println(result);
		if (result != null) {
			Map<String, Object> mapObj = (Map<String, Object>) result.getData();
			List<Map<String, Object>> mapList = (List<Map<String, Object>>) mapObj.get("printerImages");
			Map<String, Object> imgMap = null;
			for (Map<String, Object> map : mapList) {

				imgMap = new HashMap<>();
				String imageUrl = (String) map.get("imageUrl");
				String type = imageUrl.substring(imageUrl.indexOf(".") + 1);
				imgMap.put("url", imageUrl);
				imgMap.put("type", "pic");
				imgMapList.add(imgMap);
				System.out.println(imgMap);
			}

			return imgMapList;

			// {"hospitalizationNotes":[{"mr_id":"0158981","id_number":"130625284798787009","treatment_type_name":"住院","out_hospital_date":"2017-09-24","name":"赵尊号","id":5,"first_level_medical_guid":"ad820cdb37fc493aa820caa4c36c8cfd","hospital_name":"山东省立医院"}],
			// "printerImages":[{"fileName":"us7mieb4xcyudwvlqp9gs4pr73dil7pz39mfz5tyj7xn77pk0hm069kwanmgfsurzlsknx6f6w47mf6o6skks4pnupq008zyd.png","imageUrl":"http://localhost:8090/MrDoc/upload/f1/nb/c5/9x/us7mieb4xcyudwvlqp9gs4pr73dil7pz39mfz5tyj7xn77pk0hm069kwanmgfsurzlsknx6f6w47mf6o6skks4pnupq008zyd.png","fileUrl":"f1/nb/c5/9x/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"8pxy0q02xiqmo540wehzhojec5q3ygf2kq5584as88eqdug8e1868r8d99dd8vmis1zd452wubhpglee673jmys9cef0029pa.png","imageUrl":"http://localhost:8090/MrDoc/upload/g0/28/4i/jp/8pxy0q02xiqmo540wehzhojec5q3ygf2kq5584as88eqdug8e1868r8d99dd8vmis1zd452wubhpglee673jmys9cef0029pa.png","fileUrl":"g0/28/4i/jp/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"h2406mekjc6y87znj55bdcbvtcboklmjby9mqf3dj73afcuva8c4k3onibzsg8b2t7bnlvgqfymv8efj8xw8pi1jylq000adk.png","imageUrl":"http://localhost:8090/MrDoc/upload/i3/5t/67/47/h2406mekjc6y87znj55bdcbvtcboklmjby9mqf3dj73afcuva8c4k3onibzsg8b2t7bnlvgqfymv8efj8xw8pi1jylq000adk.png","fileUrl":"i3/5t/67/47/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"x5yuufuyz6j3hw1vshf7zlqhgzklkbalr9atyx7rbexq6r78qsy2kvur959tfqh438c6x24miqsi61pqm419idmh3ym001hl3.png","imageUrl":"http://localhost:8090/MrDoc/upload/wo/vq/qu/oe/x5yuufuyz6j3hw1vshf7zlqhgzklkbalr9atyx7rbexq6r78qsy2kvur959tfqh438c6x24miqsi61pqm419idmh3ym001hl3.png","fileUrl":"wo/vq/qu/oe/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"9j8stp6wophvnljgvsbrbchodwsy1ul18uyxe4xxxyx4kh41b56w4jcb524s0lg8xoksjwud1es7ugvcpyjszerip4h001qov.png","imageUrl":"http://localhost:8090/MrDoc/upload/2l/3o/s6/jg/9j8stp6wophvnljgvsbrbchodwsy1ul18uyxe4xxxyx4kh41b56w4jcb524s0lg8xoksjwud1es7ugvcpyjszerip4h001qov.png","fileUrl":"2l/3o/s6/jg/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"y0wfxmkjf2trmzrle6984i0flrt27cpo8s0tsp7ofbwly47x5bdsdq7ccr2hmawyz5iww12zl7rkbqiivhepddsll8r000vgl.png","imageUrl":"http://localhost:8090/MrDoc/upload/hy/h0/dy/lk/y0wfxmkjf2trmzrle6984i0flrt27cpo8s0tsp7ofbwly47x5bdsdq7ccr2hmawyz5iww12zl7rkbqiivhepddsll8r000vgl.png","fileUrl":"hy/h0/dy/lk/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"qtegagapmaa85v40t35s26480y5euuqxdgm9hd6oxylqmbc64vlx84098xycngl3geng74pan9uc10rrigazdmvw6ye0016cn.png","imageUrl":"http://localhost:8090/MrDoc/upload/e5/w7/mh/86/qtegagapmaa85v40t35s26480y5euuqxdgm9hd6oxylqmbc64vlx84098xycngl3geng74pan9uc10rrigazdmvw6ye0016cn.png","fileUrl":"e5/w7/mh/86/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"suphphcq4hozrdjq45ze6gtmkwyhdti3wz2seqlq5qdm1nrmuywepfrrk71fjq1onncn41c203fzdorcaneuh1i0dnm0014xq.png","imageUrl":"http://localhost:8090/MrDoc/upload/yc/4t/e9/6y/suphphcq4hozrdjq45ze6gtmkwyhdti3wz2seqlq5qdm1nrmuywepfrrk71fjq1onncn41c203fzdorcaneuh1i0dnm0014xq.png","fileUrl":"yc/4t/e9/6y/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"98k08cb5ahko2oe2qhxgyj6bto2vr8w8jpeq68vnjibbpnddi8y0h7j6bkgk1otxktjq2o6kwixbua8q5u2eo9z6uql001b5s.png","imageUrl":"http://localhost:8090/MrDoc/upload/y8/qv/o9/k0/98k08cb5ahko2oe2qhxgyj6bto2vr8w8jpeq68vnjibbpnddi8y0h7j6bkgk1otxktjq2o6kwixbua8q5u2eo9z6uql001b5s.png","fileUrl":"y8/qv/o9/k0/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"n8o47qcob4lz5jcmx50nm0mot9opppszwewo2cinctup7igj42ymt1vqxo6qjgd2ott7p7lgzq6awo5u8kzko6uxyjw001kwb.png","imageUrl":"http://localhost:8090/MrDoc/upload/y4/6z/yk/uz/n8o47qcob4lz5jcmx50nm0mot9opppszwewo2cinctup7igj42ymt1vqxo6qjgd2ott7p7lgzq6awo5u8kzko6uxyjw001kwb.png","fileUrl":"y4/6z/yk/uz/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"oo5x2ypwm29gewqi4dlteei0cr95yidfgq6f4jy0q9cqyw0ummowvhzwcuuwbwdyhd347hniye9j0i5zkjac6uqi817000jse.png","imageUrl":"http://localhost:8090/MrDoc/upload/su/lh/u9/hy/oo5x2ypwm29gewqi4dlteei0cr95yidfgq6f4jy0q9cqyw0ummowvhzwcuuwbwdyhd347hniye9j0i5zkjac6uqi817000jse.png","fileUrl":"su/lh/u9/hy/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"mlqebpl3dwd26qcv4olip1ogbw3yg8izfcnp8wrsftkjgxeeql3vsicu6bwuhwlbya5qm2d5906j20kh0ey60ua5rv7001hae.png","imageUrl":"http://localhost:8090/MrDoc/upload/od/lp/xl/tk/mlqebpl3dwd26qcv4olip1ogbw3yg8izfcnp8wrsftkjgxeeql3vsicu6bwuhwlbya5qm2d5906j20kh0ey60ua5rv7001hae.png","fileUrl":"od/lp/xl/tk/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"r8frkdtyc3x9vs2ddcn7acmptzo41ge5xod5qp1nrfurz0vbe7ewhkcd2lnp4oari7xrhgv6h122j9y3qog5sv183y2001g6r.png","imageUrl":"http://localhost:8090/MrDoc/upload/3b/bo/rx/82/r8frkdtyc3x9vs2ddcn7acmptzo41ge5xod5qp1nrfurz0vbe7ewhkcd2lnp4oari7xrhgv6h122j9y3qog5sv183y2001g6r.png","fileUrl":"3b/bo/rx/82/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"44b3j1abhy2wxoz3q5nnyserwitlsoqfxmm2p1ncjcjf2qimxubzubdic9u49sc6asst8bq6aqgp2kugma3p1kwgs3y000vbn.png","imageUrl":"http://localhost:8090/MrDoc/upload/8a/s0/z2/sa/44b3j1abhy2wxoz3q5nnyserwitlsoqfxmm2p1ncjcjf2qimxubzubdic9u49sc6asst8bq6aqgp2kugma3p1kwgs3y000vbn.png","fileUrl":"8a/s0/z2/sa/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"v5rtnb50fnio9r00ddok0bjz8drhg95tar1malw6hq3xcb21ys0c3o91sx67bvva8vzr7ybe7nup1n0n1arejofxhot000lwo.png","imageUrl":"http://localhost:8090/MrDoc/upload/do/5a/qr/s7/v5rtnb50fnio9r00ddok0bjz8drhg95tar1malw6hq3xcb21ys0c3o91sx67bvva8vzr7ybe7nup1n0n1arejofxhot000lwo.png","fileUrl":"do/5a/qr/s7/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"r4lg4vt8j98uczmx8miuiz79seg80r8hbc6sj5vl3jxlb6f996iaonqfy15ogt0hz38x0wah0q04bb2ajlcfb3kkifs000yyh.png","imageUrl":"http://localhost:8090/MrDoc/upload/sx/qw/3e/wy/r4lg4vt8j98uczmx8miuiz79seg80r8hbc6sj5vl3jxlb6f996iaonqfy15ogt0hz38x0wah0q04bb2ajlcfb3kkifs000yyh.png","fileUrl":"sx/qw/3e/wy/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"4kwjqz11a5dxjevy0h3bbfz103i1uue8gfhgdde9b16b9y30a6bdp4s23gcj7nn9i1rp3wpf96dfqhscgh6199beuds000tp7.png","imageUrl":"http://localhost:8090/MrDoc/upload/8m/b5/na/ag/4kwjqz11a5dxjevy0h3bbfz103i1uue8gfhgdde9b16b9y30a6bdp4s23gcj7nn9i1rp3wpf96dfqhscgh6199beuds000tp7.png","fileUrl":"8m/b5/na/ag/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"q3i1u1mykw9p3a7kblj7ry04x87w5q5uj3dxxqsyg5ng02atrjf1b4b2etwwbzxcjfspkv5olfauqbb8enuwzserqee000ib5.png","imageUrl":"http://localhost:8090/MrDoc/upload/c1/ym/do/z7/q3i1u1mykw9p3a7kblj7ry04x87w5q5uj3dxxqsyg5ng02atrjf1b4b2etwwbzxcjfspkv5olfauqbb8enuwzserqee000ib5.png","fileUrl":"c1/ym/do/z7/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"4qeg8j35moshv1w8hzm9y93sfptr6ta7ka99ytgkwab5kf0urcw4s4d2ccp982yzrl803dw16cpdj8lq421789ek3w9000mkw.png","imageUrl":"http://localhost:8090/MrDoc/upload/63/dz/s4/2e/4qeg8j35moshv1w8hzm9y93sfptr6ta7ka99ytgkwab5kf0urcw4s4d2ccp982yzrl803dw16cpdj8lq421789ek3w9000mkw.png","fileUrl":"63/dz/s4/2e/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"ptoqxb4jnelqdzdyglpza2ywbf5d0t8j7fakoc87bm4zh5a0mi1kvq9ojrb1q1mthhholasz6i3vvou05kumo0gu1qh000pec.png","imageUrl":"http://localhost:8090/MrDoc/upload/1g/z1/49/rt/ptoqxb4jnelqdzdyglpza2ywbf5d0t8j7fakoc87bm4zh5a0mi1kvq9ojrb1q1mthhholasz6i3vvou05kumo0gu1qh000pec.png","fileUrl":"1g/z1/49/rt/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"47tzawy8esawh25efafe0cilgu1ovnmevhszqkl5lutj53ifarx2hfu1zp7j9drevj05l1sutkmtl4bq16g3luqw79p000x32.png","imageUrl":"http://localhost:8090/MrDoc/upload/c1/lb/75/el/47tzawy8esawh25efafe0cilgu1ovnmevhszqkl5lutj53ifarx2hfu1zp7j9drevj05l1sutkmtl4bq16g3luqw79p000x32.png","fileUrl":"c1/lb/75/el/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"7ng3wwuweoj7d7p3uduk9ff7cmfem7766k6hwww24m8h2dfuol9qu0fbvrk50rgybrxin5owfgkgfbd4x48xh8leg47000snq.png","imageUrl":"http://localhost:8090/MrDoc/upload/jj/8i/ol/38/7ng3wwuweoj7d7p3uduk9ff7cmfem7766k6hwww24m8h2dfuol9qu0fbvrk50rgybrxin5owfgkgfbd4x48xh8leg47000snq.png","fileUrl":"jj/8i/ol/38/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"lo972k6ycq5hyf83pz026vnk1h3gl63x8rwumxrp51okj8skc5hsrji2y15ksavekvasoev8qcpvalcqygq9mqveuxf000xjs.png","imageUrl":"http://localhost:8090/MrDoc/upload/d5/k6/3d/p6/lo972k6ycq5hyf83pz026vnk1h3gl63x8rwumxrp51okj8skc5hsrji2y15ksavekvasoev8qcpvalcqygq9mqveuxf000xjs.png","fileUrl":"d5/k6/3d/p6/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"8ayiwbnxmjphbdw7dlusezqw8nyy85wp76pm5y90z797scm4wdqinrf5q2pzq2uo0h6tb2sinm1iecyjxgb6ro2ie4u000fgg.png","imageUrl":"http://localhost:8090/MrDoc/upload/zc/li/rj/m5/8ayiwbnxmjphbdw7dlusezqw8nyy85wp76pm5y90z797scm4wdqinrf5q2pzq2uo0h6tb2sinm1iecyjxgb6ro2ie4u000fgg.png","fileUrl":"zc/li/rj/m5/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"u1bhpqcm1qdvsxlrffj6xdzbtz126feyrogoqe6whaspb1w3wfwwfxu5msjgbh6otej1m10a16f5seeuv99dh8r4eo01015od.png","imageUrl":"http://localhost:8090/MrDoc/upload/dg/5t/8l/92/u1bhpqcm1qdvsxlrffj6xdzbtz126feyrogoqe6whaspb1w3wfwwfxu5msjgbh6otej1m10a16f5seeuv99dh8r4eo01015od.png","fileUrl":"dg/5t/8l/92/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"nr9dc0llh8h1e21frj8v9hx2meoi2bz2viufpsolphluvhdsz2t1o75zugr7ackp205nmd50ri9g3aup1h71xclinck000qux.png","imageUrl":"http://localhost:8090/MrDoc/upload/gx/f4/aa/g7/nr9dc0llh8h1e21frj8v9hx2meoi2bz2viufpsolphluvhdsz2t1o75zugr7ackp205nmd50ri9g3aup1h71xclinck000qux.png","fileUrl":"gx/f4/aa/g7/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"catletsi5w8kei4e72byhwghbkj0olzpq3lrsusiw6vnzenj943zonxr5tuf9fju23efs1kgaadexglwquepoh0nyle001pkh.png","imageUrl":"http://localhost:8090/MrDoc/upload/oi/ly/dc/71/catletsi5w8kei4e72byhwghbkj0olzpq3lrsusiw6vnzenj943zonxr5tuf9fju23efs1kgaadexglwquepoh0nyle001pkh.png","fileUrl":"oi/ly/dc/71/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"a3zl6dvo671giyg6b1fikbxmbteuwlipasy9qg273fliuwnr13hr8tbxsthi16hzu201z9l49c6uqqxkujvtfrnmbr1100z2c.png","imageUrl":"http://localhost:8090/MrDoc/upload/5q/1h/mq/we/a3zl6dvo671giyg6b1fikbxmbteuwlipasy9qg273fliuwnr13hr8tbxsthi16hzu201z9l49c6uqqxkujvtfrnmbr1100z2c.png","fileUrl":"5q/1h/mq/we/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"izoixxelx6cveqwpkipdcwk081crymwfn7ytco7m2e2apk5pfkb4fwus2w7wp2uuqkwf58a39xb6mb49j4qtvkmxijr001fda.png","imageUrl":"http://localhost:8090/MrDoc/upload/1w/39/8z/mx/izoixxelx6cveqwpkipdcwk081crymwfn7ytco7m2e2apk5pfkb4fwus2w7wp2uuqkwf58a39xb6mb49j4qtvkmxijr001fda.png","fileUrl":"1w/39/8z/mx/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"ci3ame45wpc7dusy19fzvbpz2itj9ag543l0hddet5reyvd1xtt622kkmc96z1kpn4epspohf2gx0r9rdqjykzf0p8n000yj6.png","imageUrl":"http://localhost:8090/MrDoc/upload/t3/4s/sl/wx/ci3ame45wpc7dusy19fzvbpz2itj9ag543l0hddet5reyvd1xtt622kkmc96z1kpn4epspohf2gx0r9rdqjykzf0p8n000yj6.png","fileUrl":"t3/4s/sl/wx/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"blclswdoz5cqrgsteec04yr8jvn578z0xjdo8d1z06b2vraeyatzphlf3w3rah014oorpf9n5om3325urfd233ag8zi000zpj.png","imageUrl":"http://localhost:8090/MrDoc/upload/j9/vr/pj/g7/blclswdoz5cqrgsteec04yr8jvn578z0xjdo8d1z06b2vraeyatzphlf3w3rah014oorpf9n5om3325urfd233ag8zi000zpj.png","fileUrl":"j9/vr/pj/g7/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"f9qbjwtjh1u3ymwsjpz60lngkeupa8ubdmwiy5yw9v2696f8t2djau08pn8wb2epfkjrg3vmjgyjj161ryconsu1z8c001dhh.png","imageUrl":"http://localhost:8090/MrDoc/upload/8e/xa/qk/vn/f9qbjwtjh1u3ymwsjpz60lngkeupa8ubdmwiy5yw9v2696f8t2djau08pn8wb2epfkjrg3vmjgyjj161ryconsu1z8c001dhh.png","fileUrl":"8e/xa/qk/vn/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"wpecebowbxsljj1q17x9qfjde61ch3xiw7h73k7kv5lr1kr8uqdfmch0y3k5r4fhta9nj2kgdhmwd53lqydss5yi8t310138f.png","imageUrl":"http://localhost:8090/MrDoc/upload/fa/ed/8d/5e/wpecebowbxsljj1q17x9qfjde61ch3xiw7h73k7kv5lr1kr8uqdfmch0y3k5r4fhta9nj2kgdhmwd53lqydss5yi8t310138f.png","fileUrl":"fa/ed/8d/5e/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"u12vvxi8eh6e7ia88l5q361adgu44vdubdiyknhgp7ysscnlzr33ezzz83612u2tpb1ivg1vhnze8rb7p8p5gbjpt0f000sy8.png","imageUrl":"http://localhost:8090/MrDoc/upload/rq/vl/et/t1/u12vvxi8eh6e7ia88l5q361adgu44vdubdiyknhgp7ysscnlzr33ezzz83612u2tpb1ivg1vhnze8rb7p8p5gbjpt0f000sy8.png","fileUrl":"rq/vl/et/t1/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"mlyyswh9kcfpc2ukpiv1gl5rpqnf9b588exvi2tyzsswn9640ddb5gdorts85hw3ybv2evq7nzqj9o0idghdorzhkpu000goj.png","imageUrl":"http://localhost:8090/MrDoc/upload/wx/z1/ug/7o/mlyyswh9kcfpc2ukpiv1gl5rpqnf9b588exvi2tyzsswn9640ddb5gdorts85hw3ybv2evq7nzqj9o0idghdorzhkpu000goj.png","fileUrl":"wx/z1/ug/7o/","hostUrl":"http://localhost:8090/MrDoc/upload/"},{"fileName":"cvt9ppuxnon1xeisys7lam5k8h02qn521v41zodhrk9tak08alwy7eiljm4qzzq91lcqxdaumj0im3n4g59l4ibmvde0019sf.png","imageUrl":"http://localhost:8090/MrDoc/upload/l8/zz/xb/oz/cvt9ppuxnon1xeisys7lam5k8h02qn521v41zodhrk9tak08alwy7eiljm4qzzq91lcqxdaumj0im3n4g59l4ibmvde0019sf.png","fileUrl":"l8/zz/xb/oz/","hostUrl":"http://localhost:8090/MrDoc/upload/"}]}

		}
		return null;
	}

	/* @RequiresPermissions("print:direct") */
	@RequestMapping("/queryMedPage")
	public String queryMedPage() {

		return "mailprint/queryMedPage";
	}
	
	@RequestMapping("/medPrintInfo")
	public String medPrintInfo() {

		return "print/medPrintInfo";
	}

	/**
	 * 保存病案打印登记信息
	 * 
	 * @param firstGuid
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping("/addPrintRecordPage")
	public String addPrintRecordPage(String firstGuid, Model model, HttpServletRequest request) {

		String currentUser = CookieUtils.getCookieValue(request, "userName");
		String printReason = request.getParameter("printReason");
		String copies = request.getParameter("copies");
		HospitalNote hospitalNote = applyPrintService.addHospitalNote(firstGuid);
		int copy = Integer.valueOf(copies);

		try {
			List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(firstGuid, printReason);
			model.addAttribute("printSize", markImgList.size()*copy);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		Map<String, List<Map<String, Object>>> basicMapList = basicDataService.getBaseInfoMap();
		System.out.println(basicMapList.get("relationList"));
		model.addAttribute("relationList", basicMapList.get("relationList"));
		model.addAttribute("applyReason", this.getApplyReason(Integer.valueOf(printReason)));
		model.addAttribute("hospitalNote", hospitalNote);
		model.addAttribute("printReason", printReason);
		model.addAttribute("operator", currentUser);
		model.addAttribute("picHostPath", configProperties.getServer().getCredentialPath());
		
		
		return "mailprint/addPrintRecordPage";
	}
	
	
	@RequestMapping("/printRecordPage")
	public String printRecordPage(String firstGuid, Model model, HttpServletRequest request) {

		String currentUser = CookieUtils.getCookieValue(request, "userName");
		String printReason = request.getParameter("printReason");
		String copies = request.getParameter("copies");
		HospitalNote hospitalNote = applyPrintService.addHospitalNote(firstGuid);
		int copy = Integer.valueOf(copies);

		try {
			List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(firstGuid, printReason);
			model.addAttribute("printSize", markImgList.size()*copy);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		if(hospitalNote.getOutHospitalDate()!=null){
			model.addAttribute("outHospitalDate", DateUtil.dateFormat(hospitalNote.getOutHospitalDate()));
		}
		Map<String, List<Map<String, Object>>> basicMapList = basicDataService.getBaseInfoMap();
		System.out.println(basicMapList.get("relationList"));
		model.addAttribute("relationList", basicMapList.get("relationList"));
		model.addAttribute("applyReason", this.getApplyReason(Integer.valueOf(printReason)));
		model.addAttribute("hospitalNote", hospitalNote);
		model.addAttribute("printReason", printReason);
		model.addAttribute("operator", currentUser);
		model.addAttribute("picHostPath", configProperties.getServer().getCredentialPath());
		
		
		return "print/printRecordPage";
	}

	@RequestMapping("/prePrintLittleScrip")
	public String prePrintLittleScrip() {
		return "print/prePrintLittleScrip";
	}
	
	@RequestMapping("/printLittleScrip")
	public String printLittleScrip(HttpServletRequest request, Map map) {
		String year = request.getParameter("year");
		String month = request.getParameter("month");
		String deptName1 = request.getParameter("deptName1");
		String deptName2 = request.getParameter("deptName2");
		String boxNumber1 = request.getParameter("boxNumber1");
		String boxNumber2 = request.getParameter("boxNumber2");
		
		map.put("year", year);
		map.put("month", month);
		map.put("deptName1", deptName1);
		map.put("deptName2", deptName2);
		map.put("boxNumber1", boxNumber1);
		map.put("boxNumber2", boxNumber2);
		return "print/printLittleScrip";
	}
	
	
	
	@RequestMapping("/addPrintMailRecordPage")
	public String addPrintMailRecordPage(PrintRecord printRecord, Model model, HttpServletRequest request) {
		System.out.println(printRecord);
		String currentUser = CookieUtils.getCookieValue(request, "userName");
		List<Map<String, Object>> printPicUrlList = this.getUrlListByMedRecord(printRecord.getFirstGuid(),
				printRecord.getPrintReason() + "");
		int printSize = printPicUrlList.size();
		String copies = request.getParameter("copies");
		int copy = Integer.valueOf(copies);
		printRecord.setPrintPage(printSize * copy);
		printRecord.setOperator(currentUser);
		model.addAttribute("printRecord", printRecord);
		return "mailprint/addPrintMailRecordPage";
	}

	/**
	 * 保存登记信息
	 * 
	 * @param medicalPrint
	 * @param printApplyImageIds
	 * @param firstGuid
	 * @param request
	 * @return
	 */
	@RequestMapping("/addPrintRecord")
	public String addPrintRecord(MedicalPrint medicalPrint, String printApplyImageIds, String firstGuid, String onlyId,
			 HttpServletRequest request) throws Exception{
		//System.out.println(medicalPrint);
		String currentUser = CookieUtils.getCookieValue(request, "userName");
		medicalPrint.setPrintMan(currentUser);
		
		applyPrintService.addPrintRecord(medicalPrint, firstGuid, currentUser, printApplyImageIds);

		//添加病案打印示踪记录
		Map<String, Object> treatmentTraceTypeMap = treatmentTraceTypeService.findTreatmentTraceTypeByCode("BADYDJ");
				
		if (treatmentTraceTypeMap != null) {
			  Integer traceTypeId =  treatmentTraceTypeMap.get("id") != null ? (Integer)treatmentTraceTypeMap.get("id") : null;
			  Map<String, Object> traceMap = new HashMap<String, Object>();
			  traceMap.put("firstGuid", firstGuid);
			  traceMap.put("loginName", currentUser);
			  traceMap.put("traceTypeId", traceTypeId);
			  traceMap.put("traceInfo", medicalPrint.getApplyMan() + "病案打印登记, 住院号为" + onlyId);
			  treatmentTraceService.insertTreatmentTrace(traceMap);
		} 
		
		return "mailprint/queryMedPage";
	}
	
	/**
	 * 病案邮寄登记
	 * 
	 * @param medicalMail
	 * @param firstGuid
	 * @param request
	 * @return
	 */
	@PostMapping("/addMedicalMail")
	@ResponseBody
	public Result addMedicalMail(MedicalMail medicalMail, String firstGuid, HttpServletRequest request) {
	
		try {
			String currentUser = CookieUtils.getCookieValue(request, "userName");
			applyPrintService.addMedicalMail(medicalMail, firstGuid, currentUser);
			
			return new Result(true, "添加成功!", 200);
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "添加失败!", 500);
		}
		
	}

	@RequestMapping("/addPrintMailRecord")
	public String addPrintRecord(PrintRecord printRecord, PrintMailRecord printMailRecord, HttpServletRequest request) {
		System.out.println(printRecord + "----" + printMailRecord);
		String currentUser = CookieUtils.getCookieValue(request, "userName");
		printRecord.setOperator(currentUser);
		applyPrintService.addPrintMailRecord(printRecord, printMailRecord);

		return "mailprint/queryMedPage";
	}

	// 打印详情查询
	//@RequiresPermissions("print:detail")
	@RequestMapping("/selectByPrintRecordList")
	public String selectByPrintRecordList(Model model) {
		
		return "mailprint/queryPrintDetailPage";
	}

	//@RequiresPermissions("print:maildetail")
	@RequestMapping("/queryPrintMailDetailPage")
	public String queryPrintMailDetailPage() {
		return "mailprint/queryPrintMailDetailPage";
	}

	@ResponseBody
	@RequestMapping("/getPrintMailList")
	public Result getPrintMailList(PrintRecordVo printRecordVo) {
		Map<String, Object> map = new HashMap<>();
		int count = applyPrintService.getPrintMailDetaiCount(printRecordVo);
		List<Map<String, Object>> printMailList = applyPrintService.getPrintMailDetailList(printRecordVo);
		map.put("listSize", printMailList.size());
		map.put("count", count);
		map.put("printMailList", printMailList);
		System.out.println(map);
		Result result = new Result(true, "查询成功!", map);
		return result;
	}

	@RequestMapping("exportMailListToExcel")
	public void exportMailListToExcel(HttpServletResponse response, PrintRecordVo printRecordVo) {
		List<Map<String, Object>> scanWorkMapList = new ArrayList<>();
		try {
			response.setContentType("octets/stream");
			String excelName = "邮寄详情";
			// 转码防止乱码
			response.addHeader("Content-Disposition",
					"attachment;filename=" + new String(excelName.getBytes("gb2312"), "ISO8859-1") + ".xls");
			// 通过response获取文件输出流
			OutputStream out = response.getOutputStream();
			// 查询数据
			scanWorkMapList = applyPrintService.exportMailListToExcel(printRecordVo);
			String title = "邮寄详情";
			String[] header = { "病案归属人", "病案号", "收件人姓名", "收件人地址", "收件人联系方式", "打印者", "操作" };
			ExcelUtil.exportExcel(out, title, header, scanWorkMapList);

		} catch (Exception e) {
			logger.info("统计扫描工作出现异常:异常信息=" + e.getMessage());

		}
	}

	@ResponseBody
	@RequestMapping("/updatePrintMailStatus")
	public Result updatePrintMailStatus(Integer printMailRecordId) {
		Result result = null;
		try {
			applyPrintService.updatePrintMailRecordStatus(printMailRecordId);
			result = new Result(true, "邮寄状态更新成功!");
		} catch (Exception e) {
			result = new Result(false, "邮寄状态更新失败:ex=!" + e.getMessage());
		}
		return result;
	}

	//@RequiresPermissions("print:statis")
	@RequestMapping("/printWorkTotalPage")
	public String printWorkTotalPage() {
		return "mailprint/printWorkTotalPage";
	}

	@ResponseBody
	@RequestMapping("/printWorkTotal")
	public Result printWorkTotal(PrintRecordVo printRecordVo) {
		Result result = null;
		try {
			List<Map<String, Object>> list = applyPrintService.getPrintWorkTotal(printRecordVo);
			if (list.size() > 0) {
				result = new Result(true, "查询成功", list);
			} else {
				result = new Result(false, "暂无数据!", list);
			}
		} catch (Exception e) {
			e.printStackTrace();
			result = new Result(false, "统计打印工作量出现错误:e=" + e.getMessage());
		}
		return result;
	}

	// 打印详情条件查询
	@ResponseBody
	@RequestMapping("/selectPrintRecordByCondition")
	public Result selectPrintRecordByCondition(PrintRecordVo printRecordVo) {
		Map<String, Object> map = applyPrintService.getMedicalPrintDetail(printRecordVo);
		Result result = new Result(true, "查询成功!", map);
		return result;
	}

	@RequestMapping("/exportPrintRecordToExcel")
	public void exportPrintRecordToExcel(HttpServletResponse response, PrintRecordVo printRecordVo) {
		List<Map<String, Object>> scanWorkMapList = new ArrayList<>();
		try {
			response.setContentType("octets/stream");
			String excelName = "打印详情";
			// 转码防止乱码
			response.addHeader("Content-Disposition",
					"attachment;filename=" + new String(excelName.getBytes("gb2312"), "ISO8859-1") + ".xls");
			// 通过response获取文件输出流
			OutputStream out = response.getOutputStream();
			// 查询数据
			scanWorkMapList = applyPrintService.exportPrintRecordToExcel(printRecordVo);
			String title = "打印详情";
			String[] header = { "姓名", "身份证号", "病案号", "邮寄", "打印原因", "打印页数", "打印时间", "出院时间", "操作人" };
			ExcelUtil.exportExcel(out, title, header, scanWorkMapList);

		} catch (Exception e) {
			logger.info("统计扫描工作出现异常:异常信息=" + e.getMessage());

		}
	}

	/**
	 * 导出Excel
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping("/printStaticexportExcel")
	public void printStaticexportExcel(HttpServletResponse response, PrintRecordVo printRecordVo) {
		List<Map<String, Object>> scanWorkMapList = new ArrayList<>();
		System.out.println(1);
		try {
			response.setContentType("octets/stream");
			String excelName = "打印统计";
			// 转码防止乱码
			response.addHeader("Content-Disposition",
					"attachment;filename=" + new String(excelName.getBytes("gb2312"), "ISO8859-1") + ".xls");
			// 通过response获取文件输出流
			OutputStream out = response.getOutputStream();
			// 查询数据
			scanWorkMapList = applyPrintService.getPrintWorkTotal(printRecordVo);
			String title = "打印统计";
			String[] header = { "姓名", "打印份数", "打印邮寄份数", "打印邮寄份数百分比", "打印总页数", "打印邮寄页数", "打印邮寄页数百分比" };
			ExcelUtil.exportExcel(out, title, header, scanWorkMapList);

		} catch (Exception e) {
			logger.info("统计扫描工作出现异常:异常信息=" + e.getMessage());

		}
	}

	/**
	 * 打印邮寄查询页面
	 * 
	 * @return
	 */
	//@RequiresPermissions("print:mail")
	/*@RequestMapping("/queryMailMedPrintPage")
	public String queryMailMedPrintPage(String firstGuid, Map<String, Object> map) {
		HospitalNote hospitalNote = applyPrintService.addHospitalNote(firstGuid);
		map.put("hospitalNote", hospitalNote);
		map.put("firstGuid", firstGuid);
		
		return "mailprint/queryMailMedPrintPage";
	}*/
	
	@RequestMapping("/queryMailMedPrintPage")
	public String queryMailMedPrintPage(String firstGuid, Map<String, Object> map) {
		return "mailprint/queryMailMedPrintPage";
	}

	@RequestMapping("/structuredPrint")
	public String structuredPrint() {
		return "print/structuredPrint";
	}

	@ResponseBody
	@RequestMapping("/addPhotoImg")
	public Result addPhotoImg(PrintApplyImage printApplyImage) {
		logger.info("------------------------进入添加拍摄证件图片方法-----------------------------");
		Result result = null;
		try {
			printApplyImage = applyPrintService.addMedicalPrintImage(printApplyImage);
			result = new Result(true, "保存成功!", printApplyImage);
			logger.info("------------------------添加拍摄证件图片方法成功-----------------------------");
		} catch (Exception e) {
			logger.info("------------------------添加拍摄证件图片方法异常:"+e.getMessage()+"-----------------------------");
			result = new Result(false, "保存失败!");
		}
		return result;
	}

	public String getApplyReason(Integer applyprintNum) {
		String applyReason = null;
		switch (applyprintNum) {
		case 1:
			applyReason = "门规";
			break;
		case 2:
			applyReason = "医保";
			break;
		default:
			applyReason = "其他";
			break;
		}
		return applyReason;
	}

	@SuppressWarnings("unchecked")
	public Map<String, Object> readLineFile(String filePath, String fileName) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		BufferedReader br = null;
		try {
			File destFile = new File(filePath, fileName);
			String jsonStr = null;
			if (destFile.exists()) {
				 br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath+fileName),"UTF-8"));
				jsonStr = br.readLine();
				jsonMap = JsonUtils.jsonToPojo(jsonStr, Map.class);

			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(br!=null){
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		return jsonMap;
	}

	@RequestMapping("/printToPageinfo")
	public String homePagePrint(String visitGuid, String applyReason, Model model) {
		try {

			String filePath =configProperties.getServer().getHospitalNoteJsonLocalPath()
					+ StringUtil.getLocalPath(visitGuid);
			String fileName = visitGuid + ".json";
			Map<String, Object> jsonMap = readLineFile(filePath, fileName);
			logger.info("------------------结构化打印查询水印图片开始----------------------");
			List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(visitGuid, applyReason);
			logger.info("------------------结构化打印查询水印图片结束----------------------");
			
			logger.info("------------------结构化打印查询json数据开始----------------------");
			String hospitalVisitHomePageJson = JsonUtils.objectToJson(jsonMap);
			model.addAttribute("hospitalVisitJson", JsonUtils.objectToJson(hospitalVisitHomePageJson));
			logger.info("------------------结构化打印查询json数据结束----------------------");
			
			
			List<Integer> printPageList = applyPrintService.getPrintPageByPrintType(applyReason);
			
		//	List<PrintPageDto> recordSheetList = new ArrayList<>();
			
			/*Map<String,Object> recordSheeMap=(Map<String,Object>)jsonMap.get("recordSheet");
			
			List<PrintPageDto> nurseRecordFileList = getNurseRecordFileNameList(recordSheeMap,printPageList,visitGuid);
			if(CollectionUtils.isNotEmpty(nurseRecordFileList)){
				 List<PrintPageDto> nurseList =applyPrintService.rotateImgAngle(nurseRecordFileList);
				 if(CollectionUtils.isNotEmpty(nurseList)){
				 	recordSheetList.addAll(nurseList);
				 }
			}*/
		
			
			/*List<PrintPageDto> otherRecordSheetList = getOtherRecordFileNameList(recordSheeMap,visitGuid,printPageList);
			if(CollectionUtils.isNotEmpty(otherRecordSheetList)){
				recordSheetList.addAll(otherRecordSheetList);
			}*/
			
//			if(CollectionUtils.isNotEmpty(recordSheetList)){
//				List<PrintPageDto> markList = applyPrintService.imageWaterMark(recordSheetList);
//				if(CollectionUtils.isNotEmpty(markList)){
//					markImgList.addAll(markList);
//				}
//				
//				//System.out.println(markImgList);
//				
//				//System.out.println(markImgList);
//			}
			
			Collections.sort(markImgList,new PrintPageDto());
		
			model.addAttribute("markImgList", markImgList);
			
			model.addAttribute("printPageList", printPageList);
		} catch (Exception e) {
			logger.error("------------------结构化打印异常:" + e.getMessage() + "----------------------");
			e.printStackTrace();
		}
		model.addAttribute("firstGuid", visitGuid);
		return "print/structuredPrint";
	}
	
	
	public List<PrintPageDto> getOtherRecordFileNameList(Map<String,Object> recordSheeMap,String visitGuid,List<Integer> printPageList){
		List<PrintPageDto> recordFileNameList = new ArrayList<>();
		
		PrintPageDto printPageDto = null;
		try {
		if(CollectionUtils.isEmpty(printPageList)){
			return recordFileNameList;
		}
		if(MapUtils.isEmpty(recordSheeMap)){
			return recordFileNameList;
		}
		if(printPageList.contains(46)){
			Map<String,Object> temperatureRecord = (Map<String, Object>) recordSheeMap.get("temperatureRecord");
			if(MapUtils.isNotEmpty(temperatureRecord)){
				List<String> imageFilePathList= (List<String>) temperatureRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						printPageDto = new PrintPageDto();
						printPageDto.setPrintPageType(46);
						printPageDto.setCreateDate(new Date());
						printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/tiwen/"+visitGuid+"/"+filePathName);
						//recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/tiwen/"+visitGuid+"/"+filePathName);
						recordFileNameList.add(printPageDto);
					}
				}
			}
			
			Map<String,Object> electrocardiogramRecord = (Map<String, Object>) recordSheeMap.get("electrocardiogramRecord");
			if(MapUtils.isNotEmpty(electrocardiogramRecord)){
				List<String> imageFilePathList= (List<String>) electrocardiogramRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						printPageDto = new PrintPageDto();
						printPageDto.setPrintPageType(48);
						printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/xindjc/"+visitGuid+"/"+filePathName);
						printPageDto.setCreateDate(new Date());
						//recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/xindjc/"+visitGuid+"/"+filePathName);
						recordFileNameList.add(printPageDto);
					}
				}
			}
			
			Map<String,Object> vitalSignRecord = (Map<String, Object>) recordSheeMap.get("vitalSignRecord");
			if(MapUtils.isNotEmpty(vitalSignRecord)){
				List<String> imageFilePathList= (List<String>) vitalSignRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						printPageDto = new PrintPageDto();
						printPageDto.setPrintPageType(48);
						printPageDto.setCreateDate(new Date());
						printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/smtzgc/"+visitGuid+"/"+filePathName);
						//recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/smtzgc/"+visitGuid+"/"+filePathName);
						recordFileNameList.add(printPageDto);
					}
				}
			}
			
		}
		
		/*if(printPageList.contains(50)){
			Map<String,Object> electrocardiogramRecord = (Map<String, Object>) recordSheeMap.get("electrocardiogramRecord");
			if(MapUtils.isNotEmpty(electrocardiogramRecord)){
				List<String> imageFilePathList= (List<String>) electrocardiogramRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						
						recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/xindjc/"+visitGuid+"/"+filePathName);
					}
				}
			}
			
		}*/
/*		if(printPageList.contains(54)){
			Map<String,Object> vitalSignRecord = (Map<String, Object>) recordSheeMap.get("vitalSignRecord");
			if(MapUtils.isNotEmpty(vitalSignRecord)){
				List<String> imageFilePathList= (List<String>) vitalSignRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						
						recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/smtzgc/"+visitGuid+"/"+filePathName);
					}
				}
			}
			
		}*/
		
		if(printPageList.contains(30)){
			Map<String,Object> bloodSugarRecord = (Map<String, Object>) recordSheeMap.get("bloodSugarRecord");
			if(MapUtils.isNotEmpty(bloodSugarRecord)){
				List<String> imageFilePathList= (List<String>) bloodSugarRecord.get("imageFilePathList");
				if(CollectionUtils.isNotEmpty(imageFilePathList)){
					for (String filePathName : imageFilePathList) {
						printPageDto = new PrintPageDto();
						printPageDto.setPrintPageType(30);
						printPageDto.setCreateDate(new Date());
						printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/xuetcd/"+visitGuid+"/"+filePathName);
						//recordFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/xuetcd/"+visitGuid+"/"+filePathName);
						recordFileNameList.add(printPageDto);
					}
				}
			}
			
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return recordFileNameList;
		
		
	}
	
	
	public List<PrintPageDto> getNurseRecordFileNameList(Map<String,Object> recordSheeMap,List<Integer> printPageList,String visitGuid){
		List<PrintPageDto> nurseFileNameList = new ArrayList<>();
		PrintPageDto printPageDto = null;
		if(MapUtils.isNotEmpty(recordSheeMap)){
		 	Map<String,Object> nurseRecord = (Map<String, Object>) recordSheeMap.get("nurseRecord");
		 	
		 	if(MapUtils.isNotEmpty(nurseRecord)){
//		 		if(printPageList.contains(27)){
//		 			Map<String,Object> illNurseRecord = (Map<String, Object>) nurseRecord.get("IllNurseRecord");
//			 		if(MapUtils.isNotEmpty(illNurseRecord)){
//			 			List<String> filePathNameList = (List<String>) illNurseRecord.get("imageFilePathList");
//			 			if(CollectionUtils.isNotEmpty(filePathNameList)){
//			 				for(String filePathName : filePathNameList){
//			 					printPageDto = new PrintPageDto();
//			 					printPageDto.setPrintPageType(27);
//			 					printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/bingzhj/"+visitGuid+"/"+filePathName);
//			 					nurseFileNameList.add(printPageDto);
//			 					//nurseFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/bingzhj/"+visitGuid+"/"+filePathName);
//			 				}
//			 			}
//			 		}
//			 		
//			 		Map<String,Object> criticalCareRecord = (Map<String, Object>) nurseRecord.get("criticalCareRecord");
//			 		if(MapUtils.isNotEmpty(criticalCareRecord)){
//			 			List<String> filePathNameList = (List<String>) criticalCareRecord.get("imageFilePathList");
//			 			if(CollectionUtils.isNotEmpty(filePathNameList)){
//			 				for(String filePathName : filePathNameList){
//			 					printPageDto = new PrintPageDto();
//			 					printPageDto.setPrintPageType(27);
//			 					printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/bingwhj/"+visitGuid+"/"+filePathName);
//			 					nurseFileNameList.add(printPageDto);
//			 					//nurseFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/bingwhj/"+visitGuid+"/"+filePathName);
//			 				}
//			 			}
//			 		}
//			 		
//		 		}
		 		
		 		
		 		
		 		if(printPageList.contains(49)){
		 			Map<String,Object> specialNurseRecord = (Map<String, Object>) nurseRecord.get("specialNurseRecord");
			 		if(MapUtils.isNotEmpty(specialNurseRecord)){
			 			List<String> filePathNameList = (List<String>) specialNurseRecord.get("imageFilePathList");
			 			if(CollectionUtils.isNotEmpty(filePathNameList)){
			 				for(String filePathName : filePathNameList){
			 					printPageDto = new PrintPageDto();
			 					printPageDto.setPrintPageType(49);
			 					printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/tebiehj/"+visitGuid+"/"+filePathName);
			 					nurseFileNameList.add(printPageDto);
			 					//nurseFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/tebiehj/"+visitGuid+"/"+filePathName);
			 				}
			 			}
			 		}
		 		}
		 		
		 		
		 		
		 		
//		 		if(printPageList.contains(26)){
//		 			Map<String,Object> generalNurseRecord = (Map<String, Object>) nurseRecord.get("generalNurseRecord");
//		 			if(MapUtils.isNotEmpty(generalNurseRecord)){
//		 			List<String> filePathNameList = (List<String>) generalNurseRecord.get("imageFilePathList");
//		 			if(CollectionUtils.isNotEmpty(filePathNameList)){
//		 				for(String filePathName : filePathNameList){
//		 					printPageDto = new PrintPageDto();
//		 					printPageDto.setPrintPageType(26);
//		 					printPageDto.setPrintImagePath(configProperties.getServer().getPicHostFileDir()+"CMIS/yibanhj/"+visitGuid+"/"+filePathName);
//		 					//nurseFileNameList.add(configProperties.getServer().getPicHostFileDir()+"CMIS/yibanhj/"+visitGuid+"/"+filePathName);
//		 					nurseFileNameList.add(printPageDto);
//		 				}
//		 			}
//		 		}
//		 	 	}
		 	}
		}else{
			nurseFileNameList = new ArrayList<>();
		}
		return nurseFileNameList;
	}

	@RequestMapping("/printRecordDetail")
	public String printRecordDetail(Integer medicalPrintId, Model model) {
		List<Map<String, Object>> printRecordList = applyPrintService.getPrintRecordDetail(medicalPrintId);
		if (CollectionUtils.isNotEmpty(printRecordList)) {
			model.addAttribute("medicalPrint", printRecordList.get(0));
		}
		logger.info("-------------------根据medicalPrint的id查询基本信息成功!--------------------------");
		List<Map<String, Object>> printRecordImgList = applyPrintService.getPrintRecordImg(medicalPrintId);
		logger.info("-------------------根据medicalPrint的id查询拍摄图片数据信息成功!--------------------------");
		model.addAttribute("printRecordImgList", printRecordImgList);
		model.addAttribute("totalPage", printRecordImgList.size());
		model.addAttribute("picHostPath", configProperties.getServer().getCredentialPath());
		return "mailprint/printRecordDetail";
	}
	
	
	@RequestMapping("/addMailRegistration")
	public String addMailRegistration(MailRegistraion mailRegistraion){
		
		try {
			//System.out.println(mailRegistraion);
			applyPrintService.addMailRegistartion(mailRegistraion);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "mailprint/queryMailMedPrintPage";
	}
	//邮寄登记
	@RequestMapping("/MailMedPrint")
	public String MailMedPrint() {

		return "mailprint/mailMedPrint";
	}
		//邮寄登记查询
		@RequestMapping("/queryMailMedPage")
		public String queryMailMedPage() {

			return "mailprint/queryMailMedPage";
		}
		
		@ResponseBody
		@RequestMapping("/selectPrintNumByGuid")
		public int selectPrintNumByGuid(String firstGuid) {
			 //applyPrintService.selectPrintNumByGuid(firstGuid);
			return  applyPrintService.selectPrintNumByGuid(firstGuid);
		}
		
		
		@ResponseBody
		@RequestMapping("/selectPrintCheckByGuid")
		public Map<String,Object> selectPrintCheckByGuid(String firstGuid) {
			 //applyPrintService.selectPrintNumByGuid(firstGuid);
			return  applyPrintService.selectPrintCheckByGuid(firstGuid);
		}
		
		@ResponseBody
		@RequestMapping("/printCheckByGuid")
		public int printCheckByGuid(String firstGuid) {
			 
			return  applyPrintService.printCheckByGuid(firstGuid);
		}
		
		@ResponseBody
		@RequestMapping("/selectMedPrintCheck")
		public Result selectMedPrintCheck(PrintCheckVo printCheckVo) {
			Result result = null;
			try {
				Map<String,Object> map = applyPrintService.selectMedPrintCheck(printCheckVo);
				result =new Result(true, "查询成功!", map);
			} catch (Exception e) {
				result = new Result(false);
				e.printStackTrace();
			}
			return result;
		}
		
		@ResponseBody
		@RequestMapping("/updateCheckStatus")
		public int updateCheckStatus(Integer funId) {
			applyPrintService.updateCheckStatus(funId);
			return 1;
		}
		
		
		
		@ResponseBody
		@SuppressWarnings("unchecked")
		@GetMapping("/publishPDFOfInHospitalAjax")
		public RespondResult publishPDFOfInHospitalAjax(String visitGuid, String applyReason) {
			RespondResult respondResult = null;
			try {
				String publishPath = configProperties.getServer().getPublishInHospitalPath()+visitGuid+"/"+applyReason+".pdf";
				File newFile = new File(publishPath);
				Map<String, Object> printerData = new HashMap<String, Object>();
				String filePath =configProperties.getServer().getHospitalNoteJsonLocalPath()
						+ StringUtil.getLocalPath(visitGuid);
				String fileName = visitGuid + ".json";
				Map<String, Object> jsonMap = readLineFile(filePath, fileName);
				printerData.put("medicalRecord", jsonMap.get("basicInfo"));
				if(!newFile.exists()){
					List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(visitGuid, applyReason);
					//List<PrintPageDto> publishImages = new ArrayList<PrintPageDto>();
					//List<PrintPageDto> scanImages = applyPrintService.getScanImg(visitGuid, applyReason);
					//if(CollectionUtils.isNotEmpty(scanImages)){
					//	publishImages.addAll(scanImages);
					 //}
					//List<Integer> printPageList = applyPrintService.getPrintPageByPrintType(applyReason);
					//List<PrintPageDto> recordSheetList = new ArrayList<>();
					//Map<String,Object> recordSheeMap=(Map<String,Object>)jsonMap.get("recordSheet");
					
//					List<PrintPageDto> nurseRecordFileList = getNurseRecordFileNameList(recordSheeMap,printPageList,visitGuid);
//					if(CollectionUtils.isNotEmpty(nurseRecordFileList)){
//						for (PrintPageDto printPageDto : nurseRecordFileList) {
//							printPageDto.setImageRotation(90);
//						}
//						recordSheetList.addAll(nurseRecordFileList);
//					}
//					List<PrintPageDto> otherRecordSheetList = getOtherRecordFileNameList(recordSheeMap,visitGuid,printPageList);
//					if(CollectionUtils.isNotEmpty(otherRecordSheetList)){
//						recordSheetList.addAll(otherRecordSheetList);
//					}
//					
//					if(CollectionUtils.isNotEmpty(recordSheetList)){
//						publishImages.addAll(recordSheetList);
//					}
//					
					Collections.sort(markImgList,new PrintPageDto());
					/*PDFUtil.createPdf(publishImages, publishPath);*/
					//PDFUtil.createPdf(markImgList,publishPath,configProperties.getServer().getLogoPath());
					PDFUtil.createPdf(markImgList,publishPath,configProperties.getServer().getLogoPath(),
							configProperties.getServer().getSignetPath());

				}
				printerData.put("publishFilePath", publishPath);
				printerData.put("publishFileUrl", visitGuid);
				printerData.put("publishFileName", applyReason+".pdf");
				respondResult = new RespondResult(true,RespondResult.successCode,null,printerData);
			} catch (Exception e) {
				e.printStackTrace();
				respondResult = new RespondResult(true,RespondResult.errorCode,"未知错误，请重试",null);
				return respondResult;
			}
			return respondResult;
		}
		
		@ResponseBody
		@SuppressWarnings("unchecked")
		@GetMapping("/publishPDFOfInHospitalsAjax")
		public RespondResult publishPDFOfInHospitalsAjax(String visitGuidStrs, String applyReason) {
			RespondResult respondResult = null;
			Map<String, Object> printData = new HashMap<String, Object>();
			List<Map<String,String>> printRecords = new ArrayList<Map<String,String>>();
			Date maxOutHospitalDate = null;
			Date minOutHospitalDate = null;
			try {
				String[] visitGuids = visitGuidStrs.split(",");
				for (String visitGuid : visitGuids) {
					String publishPath = configProperties.getServer().getPublishInHospitalPath()+visitGuid+"/"+applyReason+".pdf";
					File newFile = new File(publishPath);
					
					String filePath =configProperties.getServer().getHospitalNoteJsonLocalPath()
							+ StringUtil.getLocalPath(visitGuid);
					String fileName = visitGuid + ".json";
					Map<String, Object> jsonMap = readLineFile(filePath, fileName);
					Map<String, Object> basicInfo = (Map<String, Object>)jsonMap.get("basicInfo");
					if(printData.get("medicalRecord") == null){
						printData.put("medicalRecord", basicInfo);
					}
					
					if(!newFile.exists()){
						List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(visitGuid, applyReason);
						
//						
						Collections.sort(markImgList,new PrintPageDto());
						PDFUtil.createPdf(markImgList,publishPath,configProperties.getServer().getLogoPath(),
								configProperties.getServer().getSignetPath());

					}
					Map<String,String> printRecord = new HashMap<String, String>();
					printRecord.put("mrId", ObjectUtils.getStringValue(basicInfo.get("mrId")));
					printRecord.put("visitNumber", ObjectUtils.getStringValue(basicInfo.get("visitNumber")));
					printRecord.put("patientName", ObjectUtils.getStringValue(basicInfo.get("patientName")));
					Date outHospitalDateTime = DateUtil.dateParse( ObjectUtils.getStringValue(basicInfo.get("outHospitalDateTime")));
					if(maxOutHospitalDate == null){
						maxOutHospitalDate = outHospitalDateTime;
					}else{
						if(outHospitalDateTime.after(maxOutHospitalDate)){
							maxOutHospitalDate = outHospitalDateTime;
						}
					}
					
					if(minOutHospitalDate == null){
						minOutHospitalDate = outHospitalDateTime;
					}else{
						if(outHospitalDateTime.before(minOutHospitalDate)){
							minOutHospitalDate = outHospitalDateTime;
						}
					}
					
					
					printRecord.put("publishFilePath", publishPath);
					printRecord.put("publishFilePath", publishPath);
					printRecord.put("publishFileUrl", visitGuid);
					printRecord.put("publishFileName", applyReason+".pdf");
					printRecords.add(printRecord);
				}
				printData.put("printRecords", printRecords);
				printData.put("minOutHospitalDate", DateUtil.dateFormat(minOutHospitalDate));
				printData.put("maxOutHospitalDate", DateUtil.dateFormat(maxOutHospitalDate));
				respondResult = new RespondResult(true,RespondResult.successCode,null,printData);
			} catch (Exception e) {
				e.printStackTrace();
				respondResult = new RespondResult(true,RespondResult.errorCode,"未知错误，请重试",null);
				return respondResult;
			}
			return respondResult;
		}
		
		
		@RequestMapping("/publishPDFToPageinfo1")
		public void publishPDFToPageinfo1(String visitGuid, String applyReason,HttpServletResponse response) {
			
			ByteArrayOutputStream baos = null;
			OutputStream outStream = null; 
			try {

				String filePath =configProperties.getServer().getHospitalNoteJsonLocalPath()
						+ StringUtil.getLocalPath(visitGuid);
				String fileName = visitGuid + ".json";
				Map<String, Object> jsonMap = readLineFile(filePath, fileName);
				//List<PrintPageDto> publishImages = new ArrayList<PrintPageDto>();
				//List<PrintPageDto> scanImages = applyPrintService.getScanImg(visitGuid,applyReason);
				List<PrintPageDto> markImgList = applyPrintService.getScanImg(visitGuid, applyReason);
				//if(CollectionUtils.isNotEmpty(scanImages)){
				//	publishImages.addAll(scanImages);
				 //}
				List<Integer> printPageList = applyPrintService.getPrintPageByPrintType(applyReason);
				//List<PrintPageDto> recordSheetList = new ArrayList<>();
				//Map<String,Object> recordSheeMap=(Map<String,Object>)jsonMap.get("recordSheet");
				
				//List<PrintPageDto> nurseRecordFileList = getNurseRecordFileNameList(recordSheeMap,printPageList,visitGuid);
				//if(CollectionUtils.isNotEmpty(nurseRecordFileList)){
//					for (PrintPageDto printPageDto : nurseRecordFileList) {
//						printPageDto.setImageRotation(90);
//					}
//					recordSheetList.addAll(nurseRecordFileList);
//					
//				}
			
				
//				List<PrintPageDto> otherRecordSheetList = getOtherRecordFileNameList(recordSheeMap,visitGuid,printPageList);
//				if(CollectionUtils.isNotEmpty(otherRecordSheetList)){
//					recordSheetList.addAll(otherRecordSheetList);
//				}
//				
//				if(CollectionUtils.isNotEmpty(recordSheetList)){
//					publishImages.addAll(recordSheetList);
//				}
				
				Collections.sort(markImgList,new PrintPageDto());
				String publishPath = configProperties.getServer().getPublishInHospitalPath()+visitGuid+"/"+applyReason+".pdf";
				
				baos = WaterMarkUtil.getOutputStreamOfSignetByIcon(WaterMarkUtil.getOutputStreamOfWterMarkByIcon(PDFUtil.getPDFStream(markImgList), 
						configProperties.getServer().getLogoPath()),configProperties.getServer().getSignetPath());
				response.setContentLength(baos.size());
				response.setContentType("applicationf");
				response.addHeader("Content-Disposition", "inline;FileName=printer.pdf");
				outStream = response.getOutputStream(); 
				 byte[] buffer = baos.toByteArray();
				 OutputStream os = new FileOutputStream(new File("C:\\Users\\h2oco2\\Desktop\\aa.pdf"));
				 IOUtils.write(buffer, os);
		       /* outStream.write(baos.toByteArray(), 0, baos.size());  
		        outStream.flush(); */
		        
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				if(outStream != null){
					try {
						outStream.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} 
				}
				
				if(baos != null){
					try {
						baos.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}


		@RequestMapping("/publishPDFToPageinfo2")
		public void publishPDFToPageinfo2(String visitGuid, String applyReason,HttpServletResponse response) {
			
			ByteArrayOutputStream baos = null;
			OutputStream outStream = null; 
			try {

				String filePath =configProperties.getServer().getHospitalNoteJsonLocalPath()
						+ StringUtil.getLocalPath(visitGuid);
				String fileName = visitGuid + ".json";
				Map<String, Object> jsonMap = readLineFile(filePath, fileName);
				//List<PrintPageDto> publishImages = new ArrayList<PrintPageDto>();
				//List<PrintPageDto> scanImages = applyPrintService.getScanImg(visitGuid,applyReason);
				List<PrintPageDto> markImgList = applyPrintService.getPrintMarkImg(visitGuid, applyReason);
				//if(CollectionUtils.isNotEmpty(scanImages)){
				//	publishImages.addAll(scanImages);
				 //}
				List<Integer> printPageList = applyPrintService.getPrintPageByPrintType(applyReason);
				//List<PrintPageDto> recordSheetList = new ArrayList<>();
				//Map<String,Object> recordSheeMap=(Map<String,Object>)jsonMap.get("recordSheet");
				
				//List<PrintPageDto> nurseRecordFileList = getNurseRecordFileNameList(recordSheeMap,printPageList,visitGuid);
				//if(CollectionUtils.isNotEmpty(nurseRecordFileList)){
//					for (PrintPageDto printPageDto : nurseRecordFileList) {
//						printPageDto.setImageRotation(90);
//					}
//					recordSheetList.addAll(nurseRecordFileList);
//					
//				}
			
				
//				List<PrintPageDto> otherRecordSheetList = getOtherRecordFileNameList(recordSheeMap,visitGuid,printPageList);
//				if(CollectionUtils.isNotEmpty(otherRecordSheetList)){
//					recordSheetList.addAll(otherRecordSheetList);
//				}
//				
//				if(CollectionUtils.isNotEmpty(recordSheetList)){
//					publishImages.addAll(recordSheetList);
//				}
				
				Collections.sort(markImgList,new PrintPageDto());
				String publishPath = configProperties.getServer().getPublishInHospitalPath()+visitGuid+"/"+applyReason+".pdf";
				PDFUtil.createPdf(markImgList, publishPath);
				baos = PDFUtil.getPDFStream(markImgList);
				response.setContentLength(baos.size());
				response.setContentType("application/pdf");
				response.addHeader("Content-Disposition", "inline;FileName=printer.pdf");
				outStream = response.getOutputStream(); 
				 
		        outStream.write(baos.toByteArray(), 0, baos.size());  
		        outStream.flush(); 
		        
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				if(outStream != null){
					try {
						outStream.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} 
				}
				
				if(baos != null){
					try {
						baos.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
		
		
		
		
		@RequestMapping("/markPrint")
		public String markPrint(){
			return "print/markPrint";
		}
		
		
		
	
}
